import 'package:flutter/material.dart';
import 'package:lcapp/routes/home/home_route.dart';
import 'package:lcapp/routes/min/min_route.dart';
import 'login/login_route.dart';

class ASRRoute {
  static GlobalKey<NavigatorState> navigatorKey = GlobalKey();
  ASRRoute() {
    routes.addAll(LoginRoutes.routes); //登录相关的路由
    routes.addAll(HomeRoutes.routes);
    routes.addAll(MinRoutes.routes);
  }
  Map routes = {};

  Route onGenerateRoute(RouteSettings settings) {
    // 统一处理
    final String? name = settings.name;
    final Function pageContentBuilder = routes[name];
    if (pageContentBuilder != null) {
      if (settings.arguments != null) {
        final Route route = MaterialPageRoute(
            settings: RouteSettings(name: name, arguments: settings.arguments),
            builder: (context) =>
                pageContentBuilder(context, arguments: settings.arguments));
        return route;
      }else{
        final Route route = MaterialPageRoute(
            settings: RouteSettings(name: name, arguments: settings.arguments),
            builder: (context) =>
                pageContentBuilder(context,));
        return route;
      }
    }
    final Route route = MaterialPageRoute(
        settings: RouteSettings(name: name, arguments: settings.arguments),
        builder: (context) => pageContentBuilder(context));
    return route;
  }
}
